package com.agenda.server.recebedores;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import com.agenda.comum.ObjectRecebedorInformacao;
import com.agenda.controller.CompromissoController;
import com.agenda.controller.StatusController;
import com.agenda.model.RespostaRequisicao;
import com.agenda.model.StatusServidor;
import com.agenda.model.Usuario;
import com.agenda.server.Servidor;

public class VerificarStatusRecebedor extends ObjectRecebedorInformacao {

	@Override
	public void receber(Socket sck) throws Exception {
		this.sck = sck;
		resposta = new RespostaRequisicao(false, "");
	}

	@Override
	public void receber(ObjectInputStream objectInput) throws Exception {

	}

	@Override
	protected void responder(OutputStream outputStream) throws Exception {

		ArrayList<Usuario> usuariosOnLine = Servidor.getInstancia().getUsuariosOnline();
		List<String> status = new ArrayList<String>();
		for (Usuario usuario : usuariosOnLine)
			status.add(StatusController.getINSTANCIA().retornarStatus(usuario));

		StatusServidor statusServidor = new StatusServidor();

		statusServidor.setUsuariosOnLine(usuariosOnLine);

		statusServidor.setStatusUsuariosOnLine(status);

		statusServidor.setCompromissos(CompromissoController.getINSTANCIA().getProximosCompromissos());

		ObjectOutputStream objOutput = new ObjectOutputStream(sck.getOutputStream());
		objOutput.writeObject(statusServidor);
	}

}
